package com.sikao.app.adapter;

import android.content.Context;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sikao.app.R;
import com.sikao.app.bean.TenderBidBean;
import com.sikao.app.myinterface.CallbackOne;

import java.util.List;

/**
 * Created by Administrator on 2016/8/10.
 */
public class TenderBidRecordAdapter extends BaseAdapter {

	private Context context;
	private List<TenderBidBean.ResBean.ListBean> beans;
	private CallbackOne callbackOne;

	public TenderBidRecordAdapter(Context context, List<TenderBidBean.ResBean.ListBean> beans, CallbackOne callbackOne) {
		this.context = context;
		this.beans = beans;
		this.callbackOne = callbackOne;
	}

	@Override
	public int getCount() {
		return beans.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		View view;
		ViewHolder viewHolder;
		if (convertView == null) {
			view = View.inflate(context, R.layout.tender_bid_record_list_item, null);
			viewHolder = new ViewHolder(view);
			view.setTag(viewHolder);
		} else {
			view = convertView;
			viewHolder = (ViewHolder) view.getTag();
		}
		viewHolder.tvname.setText(beans.get(position).getName());
		viewHolder.tvprice.setText(beans.get(position).getPrice());
		viewHolder.tvpriceunit.setText(beans.get(position).getUnit());
		viewHolder.tvtitle.setText(beans.get(position).getTitle());
		viewHolder.tvamount.setText(beans.get(position).getAmount());
		viewHolder.tvamountunit.setText(beans.get(position).getUnit());
		viewHolder.tvtime.setText(beans.get(position).getAdd_time_str());
		if (beans.get(position).getResult().equals("0")) {
			viewHolder.btn1.setText("拒绝");
			viewHolder.btn2.setText("接受");
			viewHolder.btn2.setTextColor(context.getResources().getColor(R.color.white));
			viewHolder.btn1.setVisibility(View.VISIBLE);
			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
				viewHolder.btn2.setBackground(context.getResources().getDrawable(R.drawable.selector_btn_red_five));
			}
			viewHolder.btn1.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					callbackOne.notice("no", position);
				}
			});
			viewHolder.btn2.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					callbackOne.notice("yes", position);
				}
			});
		} else if (beans.get(position).getResult().equals("1")) {
			viewHolder.btn2.setText("已接受");
			viewHolder.btn2.setTextColor(context.getResources().getColor(R.color.text_lighter_gray));
			viewHolder.btn1.setVisibility(View.GONE);
			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
				viewHolder.btn2.setBackground(context.getResources().getDrawable(R.drawable.shap_white_solid_gray_stroke_five));
			}
		} else if (beans.get(position).getResult().equals("2")) {
			viewHolder.btn2.setText("已拒绝");
			viewHolder.btn2.setTextColor(context.getResources().getColor(R.color.text_lighter_gray));
			viewHolder.btn1.setVisibility(View.GONE);
			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
				viewHolder.btn2.setBackground(context.getResources().getDrawable(R.drawable.shap_white_solid_gray_stroke_five));
			}
		}else if (beans.get(position).getResult().equals("3")) {
			viewHolder.btn2.setText("已撤销");
			viewHolder.btn2.setTextColor(context.getResources().getColor(R.color.text_lighter_gray));
			viewHolder.btn1.setVisibility(View.GONE);
			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
				viewHolder.btn2.setBackground(context.getResources().getDrawable(R.drawable.shap_white_solid_gray_stroke_five));
			}
		}

		return view;
	}

	public class ViewHolder {
		public final TextView tvname;
		public final TextView tvprice;
		public final TextView tvpriceunit;
		public final TextView tvtime;
		public final TextView tvtitle;
		public final TextView tvamount;
		public final TextView tvamountunit;
		public final Button btn2;
		public final Button btn1;
		public final View root;

		public ViewHolder(View root) {
			tvname = (TextView) root.findViewById(R.id.tv_name);
			tvprice = (TextView) root.findViewById(R.id.tv_price);
			tvpriceunit = (TextView) root.findViewById(R.id.tv_price_unit);
			tvtime = (TextView) root.findViewById(R.id.tv_time);
			tvtitle = (TextView) root.findViewById(R.id.tv_title);
			tvamount = (TextView) root.findViewById(R.id.tv_amount);
			tvamountunit = (TextView) root.findViewById(R.id.tv_amount_unit);
			btn2 = (Button) root.findViewById(R.id.btn2);
			btn1 = (Button) root.findViewById(R.id.btn1);
			this.root = root;
		}
	}
}
